#ifndef YANIMATIONGROUP_H
#define YANIMATIONGROUP_H

#include "Animation.h"

#include <vector>

namespace Y{

class AnimationGroup: public AnimationBase{
	
	public:
		
		std::vector< AnimationBase * > anims;
		
	public:
	
		AnimationGroup( Entity *parentis = NULL ):
			AnimationBase(parentis)
		{}
		
		virtual ~AnimationGroup(){
			for ( int i = 0; i < anims.size(); ++i ){
				delete anims[i];
			}
		}
		
		virtual void handleConfig ( ConfigVector& cv ){
			for ( int i = 0; i < cv.size(); ++i ){
				if ( cv[i].name == "animation" ){
					addAnimation( cv[i].to< AnimationBase * >() );
					handled();
				}
			}
			AnimationBase::handleConfig(cv);
		}
		
		virtual void addAnimation ( AnimationBase *a ){ 
			anims.push_back( a );
			a->connect( "killed" , this, FUNC( AnimationGroup,removeAnimation,int ), (int) (anims.size() - 1) );
		}
		
		virtual void removeAnimation ( int i ){
			anims[i] = NULL;
			for ( int i = 0; i < anims.size(); ++i ){
				if ( anims[i] != NULL ){
					return;
				}
			}
			
			end();
		}
		
		
		virtual void timer (float f){	
		}
		
		virtual void activate (){ 
			for ( int i = 0;i  < anims.size(); ++i ){ anims[i]->activate(); }
		}
		
		virtual void deactivate () { 
			for( int i = 0; i < anims.size(); ++i ){
				anims[i]->deactivate();
			}
		}
		
		virtual void end  () {
			anims.clear();
			AnimationBase::end();
		}
	
};

}
#endif
